<script lang="ts" setup name="LoginCallback">
import LoginHeader from './components/LoginHeader.vue'
import LoginFooter from './components/LoginFooter.vue'
// 已有账号绑定手机组件
import CallbackBind from './components/CallbackBind.vue'
// 没有小兔鲜账号，请完善资料组件
import CallbackPatch from './components/CallbackPatch.vue'
import { ref } from 'vue'
import useStore from '@/store'
import { useRouter } from 'vue-router'
import Message from '@/components/XtxMessage'
const router = useRouter()
const { user } = useStore()

// 是否有小兔仙账号
const hasAccount = ref(true)

// QQ登录
if (QC.Login.check()) {
    QC.Login.getMe(async (openId) => {
        // 调用QQ登录函数
        await user.loginQQ(openId)
        Message.success('恭喜您, 登录成功!')
        // 跳转首页
        router.push('/')

    })
}
</script>

<template>
    <LoginHeader>QQ登录</LoginHeader>
    <section class="container">
        <nav class="tab">
            <a @click="hasAccount = true" :class="{ active: hasAccount }" href="javascript:;">
                <i class="iconfont icon-bind" />
                <span>已有小兔鲜账号，请绑定手机</span>
            </a>
            <a @click="hasAccount = false" :class="{ active: !hasAccount }" href="javascript:;">
                <i class="iconfont icon-edit" />
                <span>没有小兔鲜账号，请完善资料</span>
            </a>
        </nav>
        <!-- 绑定手机 -->
        <div class="tab-content" v-if="hasAccount">
            <CallbackBind />
        </div>
        <!-- 完善资料 -->
        <div class="tab-content" v-else>
            <CallbackPatch />
        </div>
    </section>
    <LoginFooter />
</template>

<style scoped lang="less">
.container {
    padding: 25px 0;
}

.tab {
    background: #fff;
    height: 80px;
    padding-top: 40px;
    font-size: 18px;
    text-align: center;

    a {
        color: #666;
        display: inline-block;
        width: 350px;
        line-height: 40px;
        border-bottom: 2px solid #e4e4e4;

        i {
            font-size: 22px;
            vertical-align: middle;
        }

        span {
            vertical-align: middle;
            margin-left: 4px;
        }

        &.active {
            color: @xtxColor;
            border-color: @xtxColor;
        }
    }
}

.tab-content {
    min-height: 600px;
    background: #fff;
}
</style>